package com.quark.web.ui.field;

import java.util.List;

import com.quark.data.type.QuarkPair;
import com.quark.data.type.QuarkVariable;
import com.quark.framework.ormapping.QuarkOrmEntity;
import com.quark.framework.utility.QuarkLog;
import com.quark.framework.utility.QuarkUtilHtmlEscape;
import com.quark.web.ui.base.QuarkUiBoldElement;

public class QuarkUiMultipleUploadField extends QuarkUiFieldBase {

	QuarkUiBoldElement element = null;
	
	public QuarkUiMultipleUploadField(String fieldName) {
		super(fieldName, new QuarkUiBoldElement(fieldName, fieldName, "", "", false));
		// TODO Auto-generated constructor stub
		element = (QuarkUiBoldElement) elementBase;
		rowspan = 2;
		//TODO Add a attribute for js
		element.addAttribute("uploaderex", "");
	}
	
	public String createField()
	{
		return element.createElement();
	}
	
	public void clearField()
	{
		super.clearField();
		//TODO remove attribute for javascript
		return; 
	}
	
	public boolean fillFieldWith(Object param)
	//Accept x,x,x;x,x,x;x,x,x;
	//consider List<QuarkPair<String, String>> / QuarkPair<String, String>[]
	{
		clearField();
		if(param != null)
		{
			if(param.getClass().equals(String.class))
			{
				element.addAttribute("uploaderex", "uploaded:'" + param.toString() + "'");
			}
			return true;
/*
			if(param.getClass().equals(List.class))
			{
				List<?> list = (List<?>)param;			
				for(Object i : list)
				{
					QuarkPair<?, ?> pair = (QuarkPair<?, ?>)i;
					//TODO Add Attribute for javascript
				}
				return true;
			}
			else if(
					param.getClass().isArray() && 
					param.getClass().getComponentType().equals(Integer.class)
					)
			{
				Object[] array = (Object[]) param;
				for(Object i : array)
				{
					QuarkPair<?, ?> pair = (QuarkPair<?, ?>)i;
					//TODO Add Attribute for javascript
				}
				return true;
			}
			else
			{
				QuarkLog.logError(
						getClass().getName(), 
						"can't fill with " + 
						param.getClass().getName() + 
						", " + 
						List.class.getName() + 
						"<QuarkPair<String, Object>> or QuarkPair<String, Object> expected"
						);
				return false;
			}
*/
		}
		else
		{
			QuarkLog.logError(getClass().getName(), "can't fill with " + getClass().getName());
			return false;
		}
	}

}
